package cn.smartorigin.soas.frame.menubar;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.TexturePaint;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JMenuBar;
import javax.swing.border.Border;

import cn.smartorigin.soas.frame.SoasUtil;

public class CellMenuBar extends JMenuBar{
//	private ImageIcon backgroundImageIcon =  new ImageIcon("img/menubar/statusbar_background.png");
    private Image backgroundImageURL = new ImageIcon("img/menubar/menubar_background.png").getImage();
    private Image backgroundLeftImage = new ImageIcon("img/menubar/menubar_background_left.png").getImage();
    private Image backgroundRightImage = new ImageIcon("img/menubar/menubar_background_right.png").getImage();
    
    
    private TexturePaint paint = SoasUtil.createTexturePaint(backgroundImageURL);
	
//    private JPanel leftPane = new JPanel(new BorderLayout());
//    private JPanel rightPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    private Border border = BorderFactory.createEmptyBorder();
    
    public CellMenuBar(){
    	init();
    }
    
    private void init() {
    	this.setBorder(border);
    }
    

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        //paint center image.
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(paint);
        g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
        
        //paint left side image.
        g2d.drawImage(backgroundLeftImage, 0, 0, null);
        
        //paint right side image.
        g2d.drawImage(backgroundRightImage, this.getWidth() - backgroundRightImage.getWidth(null), 0, null);
    }
    
    @Override
    public Dimension getPreferredSize() {
 //       return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight());
    	return new Dimension(super.getPreferredSize().width, backgroundImageURL.getHeight(null));
    }
}
